package com.zzedu.framework.interceptor;

import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Parenthesis;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;

/**
 * 数据权限插件
 */
public class MyDataPermissionHandler implements DataPermissionHandler {
    @Override
    public Expression getSqlSegment(Expression where, String mappedStatementId) {
        Expression permissionExpression = DataFilterScopeContext.getDataFilterScope();
        if (null != permissionExpression) {
            return new AndExpression(where, new Parenthesis(permissionExpression));
        }
        return where;
    }

}
